package com.njlime.member.repository.app;

import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.utils.DateUtil;
import com.njlime.member.entiies.MemberTrack;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Dean on 2017/10/9.
 */
@Repository
public class AppMemberTrackDaoImpl extends BaseDaoImpl<MemberTrack> {

    /**
     * 获取当天阅读记录
     * @param uid
     * @param businessType
     * @param businessId
     * @return
     */
    public Map<String,Object> getTodayTrack(Integer uid, Integer businessType, Integer businessId) {
        StringBuffer sb = new StringBuffer();
        sb.append("select * from t_member_track ");
        List<Object> arrList = new ArrayList<Object>();
        sb.append(" where member_id = ? and business_type = ? and business_id = ? and create_time > ? ");
        arrList.add(uid);
        arrList.add(businessType);
        arrList.add(businessId);
        arrList.add(DateUtil.getDayStart(new Date()));
        List<Map<String, Object>> beanList = getListJdbc(sb.toString(), arrList);
        if(beanList!=null && beanList.size()>0){
            return beanList.get(0);
        }else {
            return null;
        }
    }
}
